<template>
    <div class="shoucang-page">
        <!-- 头部标题 -->
        <header class="shoucang-header">
            <h2>我的收藏</h2>
        </header>

        <!-- 收藏管理 -->
        <div class="address-section panel">
            <!-- 收藏管理部分 -->
            <el-table :data="shoucangInfo" class="result-table">
                <el-table-column label="收藏ID" prop="scid"></el-table-column>
                <el-table-column label="收藏商家" prop="sjid"></el-table-column>
                <el-table-column label="操作" width="100">
                    <template #default="scope">
                        <el-button type="primary" @click="doDelete(scope.row)">取消收藏</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import axios from 'axios';
import { useUserStore } from "../stores/user.ts";
import { storeToRefs } from "pinia";
import {ElLoading} from "element-plus";

// 收藏列表
const shoucangInfo = ref([]);
// 状态管理
const userStore = useUserStore();
const { userInfo } = storeToRefs(userStore);
const shoucang = ref({
    scid:'',
    yhid:'',
    sjid:'',
})

const doDelete = async (obj) => {
  const {data} = await axios.delete('/api/shoucang/'+obj.scid,)
    if(data.code === 200){

        getShoucangList();
    }
}

// 获取收藏数据
const getShoucangList = async () => {
    shoucang.value.yhid = JSON.parse(localStorage.getItem('userInfo') || 'null').yhid;
    const{data} = await axios.get('/api/shoucang',
        {
            params: {
                ...shoucang.value,
            }
        })
    if (data.code === 200) {
        shoucangInfo.value = [];
        shoucangInfo.value = data.data.records;
    }
};
onMounted(() => {
    getShoucangList();
});
</script>

<style scoped>
.shoucang-page {
    font-family: "Microsoft YaHei", sans-serif;
    background-color: #f5f5f5;
    min-height: 100vh;
    color: #333;
    margin: 0;
    padding: 0;
}

/* 头部样式 */
.shoucang-header {
    background-color: #f58147;
    color: white;
    padding: 16px;
    text-align: center;
}

.shoucang-header h2 {
    margin: 0;
    font-size: 18px;
}

/* 加载状态 */
.loading-state {
    text-align: center;
    padding: 20px;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 20px;
}

/* 收藏列表 */
.shoucang-list {
    padding: 10px;
}

.shoucang-item {
    background-color: white;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}
</style>